home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tex / macros / source / contrib / supported / calc / calc.sty (.txt) < prev   
LaTeX Document  |  1995-03-15  |  6KB  |  143 lines

  1. %% This is file `calc.sty', generated 
  2. %% on <1995/3/4> with the docstrip utility (2.2i).
  3. %% The original source files were:
  4. %% calc.dtx  (with options: `package')
  5. %% File `calc.dtx'.
  6. %% Copyright (C) 1992--1994 Kresten Krab Thorup and Frank Jensen.
  7. %% All rights reserved.
  8. \def\fileversion{v4.0b (TEST)}
  9. \def\filedate{95/02/09}
  10. %% \CharacterTable
  11. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  12. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  13. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  14. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  15. %%   Dollar        \$     Percent       \%     Ampersand     \&
  16. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  17. %%   Asterisk      \*     Plus          \+     Comma         \,
  18. %%   Minus         \-     Point         \.     Solidus       \/
  19. %%   Colon         \:     Semicolon     \;     Less than     \<
  20. %%   Equals        \=     Greater than  \>     Question mark \?
  21. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  22. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  23. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  24. %%   Right brace   \}     Tilde         \~}
  25. \NeedsTeXFormat{LaTeX2e}
  26. \ProvidesPackage{calc}[\filedate\space\fileversion]
  27. \typeout{Package: `calc' \fileversion\space <\filedate> (KKT and FJ)}
  28. \def\calc@assign@generic#1#2#3#4{\let\calc@A#1\let\calc@B#2%
  29.     \calc@open(#4!\global\calc@A\calc@B\endgroup#3\calc@B}
  30. \def\calc@assign@count{\calc@assign@generic\calc@Acount\calc@Bcount}
  31. \def\calc@assign@dimen{\calc@assign@generic\calc@Adimen\calc@Bdimen}
  32. \def\calc@assign@skip{\calc@assign@generic\calc@Askip\calc@Bskip}
  33. \newcount\calc@Acount   \newcount\calc@Bcount
  34. \newdimen\calc@Adimen   \newdimen\calc@Bdimen
  35. \newskip\calc@Askip     \newskip\calc@Bskip
  36. \def\setcounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
  37.    {\calc@assign@count{\global\csname c@#1\endcsname}{#2}}}
  38. \def\addtocounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
  39.    {\calc@assign@count{\global\advance\csname c@#1\endcsname}{#2}}}
  40. \DeclareRobustCommand\setlength{\calc@assign@skip}
  41. \DeclareRobustCommand\addtolength[1]{\calc@assign@skip{\advance#1}}
  42. \def\calc@pre@scan#1{%
  43.    \ifx(#1%
  44.        \let\calc@next\calc@open
  45.    \else
  46.        \let\calc@next\calc@numeric
  47.    \fi
  48.    \calc@next#1}
  49. \def\calc@open({\begingroup\aftergroup\calc@initB
  50.    \begingroup\aftergroup\calc@initB
  51.    \calc@pre@scan}
  52. \def\calc@initB{\calc@B\calc@A}
  53. \def\calc@numeric{\afterassignment\calc@post@scan \global\calc@A}
  54. \def\calc@post@scan#1{%
  55.    \ifx#1!\let\calc@next\endgroup \else
  56.     \ifx#1+\let\calc@next\calc@add \else
  57.      \ifx#1-\let\calc@next\calc@subtract \else
  58.       \ifx#1*\let\calc@next\calc@multiplyx \else
  59.        \ifx#1/\let\calc@next\calc@dividex \else
  60.         \ifx#1)\let\calc@next\calc@close \else \calc@error#1%
  61.         \fi
  62.        \fi
  63.       \fi
  64.      \fi
  65.     \fi
  66.    \fi
  67.    \calc@next}
  68. \def\calc@add{\calc@generic@add\calc@addAtoB}
  69. \def\calc@subtract{\calc@generic@add\calc@subtractAfromB}
  70. \def\calc@generic@add#1{\endgroup\global\calc@A\calc@B\endgroup
  71.    \begingroup\aftergroup#1\begingroup\aftergroup\calc@initB
  72.    \calc@pre@scan}
  73. \def\calc@addAtoB{\advance\calc@B\calc@A}
  74. \def\calc@subtractAfromB{\advance\calc@B-\calc@A}
  75. \def\calc@multiplyx#1{\def\calc@tmp{#1}%
  76.    \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@multiply \else
  77.       \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@multiply \else
  78.          \let\calc@next\calc@multiply
  79.       \fi
  80.    \fi
  81.    \calc@next#1}
  82. \def\calc@dividex#1{\def\calc@tmp{#1}%
  83.    \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@divide \else
  84.       \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@divide \else
  85.          \let\calc@next\calc@divide
  86.       \fi
  87.    \fi
  88.    \calc@next#1}
  89. \def\calc@ratio@x{\ratio}
  90. \def\calc@real@x{\real}
  91. \def\calc@multiply{\calc@generic@multiply\calc@multiplyBbyA}
  92. \def\calc@divide{\calc@generic@multiply\calc@divideBbyA}
  93. \def\calc@generic@multiply#1{\endgroup\begingroup
  94.    \let\calc@A\calc@Acount \let\calc@B\calc@Bcount
  95.    \aftergroup#1\calc@pre@scan}
  96. \def\calc@multiplyBbyA{\multiply\calc@B\calc@Acount}
  97. \def\calc@divideBbyA{\divide\calc@B\calc@Acount}
  98. \def\calc@close
  99.    {\endgroup\global\calc@A\calc@B
  100.     \endgroup\global\calc@A\calc@B
  101.     \calc@post@scan}
  102. \def\calc@ratio@multiply\ratio{\calc@ratio@evaluate}
  103. \def\calc@ratio@divide\ratio#1#2{\calc@ratio@evaluate{#2}{#1}}
  104. \let\calc@numerator=\calc@Bcount
  105. \newcount\calc@denominator
  106. \def\calc@ratio@evaluate#1#2{%
  107.    \endgroup\begingroup
  108.       \calc@assign@dimen\calc@numerator{#1}%
  109.       \calc@assign@dimen\calc@denominator{#2}%
  110.       \gdef\calc@the@ratio{}%
  111.       \ifnum\calc@numerator<0 \calc@numerator-\calc@numerator
  112.          \gdef\calc@the@ratio{-}%
  113.       \fi
  114.       \ifnum\calc@denominator<0 \calc@denominator-\calc@denominator
  115.          \xdef\calc@the@ratio{\calc@the@ratio-}%
  116.       \fi
  117.       \calc@Acount\calc@numerator
  118.       \divide\calc@Acount\calc@denominator
  119.       \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount.}%
  120.       \calc@next@digit \calc@next@digit \calc@next@digit
  121.       \calc@next@digit \calc@next@digit \calc@next@digit
  122.    \endgroup
  123.    \calc@multiply@by@real\calc@the@ratio
  124.    \begingroup
  125.    \calc@post@scan}
  126. \def\calc@next@digit{%
  127.       \multiply\calc@Acount\calc@denominator
  128.       \advance\calc@numerator -\calc@Acount
  129.       \multiply\calc@numerator 10
  130.       \calc@Acount\calc@numerator
  131.       \divide\calc@Acount\calc@denominator
  132.       \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount}}
  133. \def\calc@multiply@by@real#1{\calc@Bdimen #1\calc@B \calc@B\calc@Bdimen}
  134. \def\calc@real@multiply\real#1{\endgroup
  135.    \calc@multiply@by@real{#1}\begingroup
  136.    \calc@post@scan}
  137. \def\calc@real@divide\real#1{\calc@ratio@evaluate{1pt}{#1pt}}
  138. \def\calc@error#1{%
  139.    \errhelp{Calc error: I expected to see one of: + - * / )}%
  140.    \errmessage{Invalid character `#1' in arithmetic expression}}
  141. \endinput
  142. %% End of file `calc.sty'.
  143.